package goroutine

import (
	"fmt"
	"sync"
)

func RunCond() {

	cond := sync.NewCond(&sync.Mutex{})
	count := 0

	var stuSlice []int

	for i := 0; i < 30; i++ {
		go func(i int) {
			cond.L.Lock()
			stuSlice = append(stuSlice, i)
			count++
			cond.L.Unlock()

			cond.Broadcast()
		}(i)
	}

	//调用Wait前必须持有锁
	cond.L.Lock()
	for count != 30 {
		cond.Wait()
	}

	fmt.Println(len(stuSlice),stuSlice)

}
